package com.handinfo.android.uicontrols.controls;

import android.graphics.Bitmap;
import android.graphics.PointF;

import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.utils.Tools;

/**
 * 进度条控件
 * @author handinfo
 */
public class DWScrollBar extends DWControl
{

	private int m_mark = 0;//刻度
	private Bitmap img_mark = null;//滚动条中间刻度
	private Bitmap img_rect = null;//中间背景
//	private int m_backup_h = 8;//预留高度
	
	public DWScrollBar(int h)
	{
		initImage();
		setShowWideHigh(img_rect.getWidth(), h);
	}

	public DWScrollBar(int x, int y, int h)
	{
		initImage();
		setPoint(x, y);
		setShowWideHigh(img_rect.getWidth(), h);
	}

	private void initImage()
	{
		img_mark = DWControlsManager.getInstance().createControlImage(DWControlsManager.RES_SCROLLBAR_MARK);
		img_rect = DWControlsManager.getInstance().createControlImage(DWControlsManager.RES_SCROLLBAR_RECT);
	}

	public void render(DWGraphics g)
	{
		if (img_rect != null && img_mark != null) {
			setClip(g);
			g.drawBitmap(img_rect, m_show_x, m_show_y, m_show_w, m_show_h, Tools.LEFT_TOP);
			if (m_mark >= 0) {
				int x = m_show_x + 3;
				int y = m_show_y + m_mark * (m_show_h - img_mark.getHeight()) / 100;
				g.drawBitmap(img_mark, x, y, Tools.LEFT_TOP);
			}
		}
	}

	public void renderLimits(DWGraphics g, int x, int y, int w, int h, int offsetx, int offsety)
	{
		if (img_rect != null && img_mark != null) {
			setSubClip(g, x, y, w, h, offsetx, offsety);
			g.drawBitmap(img_rect, x + m_show_x - offsetx, y + m_show_y - offsety, m_show_w, m_show_h, Tools.LEFT_TOP);
			if (m_mark >= 0) {
				int tx = x + m_show_x + 3 - offsetx;
				int ty = y + m_show_y + m_mark * (m_show_h - img_mark.getHeight()) / 100 - offsety;
				g.drawBitmap(img_mark, tx, ty, Tools.LEFT_TOP);
			}
		}
	}

	/**
	 * 设置刻度
	 * @param mark
	 */
	public void setMark(int mark)
	{
		m_mark = mark;
	}
	
	/**
	 * 得到当前刻度
	 * @return
	 */
	public int getMark() {
		return m_mark;
	}

	public void logic()
	{

	}
	
	public boolean doScroll(PointF start, PointF end, float distanceX, float distanceY)
	{
		return false;
	}

	public boolean doClick(float pointX, float pointY)
	{
		return false;
	}

}
